﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MHYS.DEMO.Model;
using MHYS.DEMO.DAL;
namespace MEYS.DEMO.BLL
{
    public class UserInfoManager
    {


        /// <summary>
        /// 登陆
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <param name="Pwd">密码</param>
        /// <returns>登陆是否成功</returns>
        public static bool CheckLogin(string userName, string Pwd)
        {
            try
            {
                if (Pwd == UserInfoService.SelectUserInfo(userName).FirstOrDefault().UserPwd.ToString())
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception ex)
            {
                return false;
            }
        }

        /// <summary>
        /// 返回用户信息
        /// </summary>
        /// <param name="userName">用户名</param>
        /// <returns>用户实体</returns>
        public static UserInfo ShowUserInfo(string userName)
        {
            return UserInfoService.SelectUserInfo(userName).FirstOrDefault();
        }

        /// <summary>
        /// 更新实体
        /// </summary>
        /// <param name="user">用户实体</param>
        /// <returns>是否更新成功</returns>
        public static bool UpdateUserInfo(UserInfo user)
        {
            if (UserInfoService.UpdateUserInfo(user))
            {

                return true;
            }
            else
            {
                return false;
            }
        }

        /// <summary>
        /// 注册
        /// </summary>
        /// <param name="user">用户实体</param>
        /// <returns>是否注册成功</returns>
        public static bool RegisterUser(UserInfo user) {
          return  UserInfoService.InsertUser(user);
        }


    }
}
